component extends="Controller" output="false" {
  
  public void function init(){
  }
  
  // clubs/index
  public void function index(){
    clubs = model("Club").findAll();
  }
  
  // clubs/show/key
  public void function show(){
    club = model("Club").findByKey(params.key);
    	
    if (!IsObject(club)){
      flashInsert(error="Club #params.key# was not found");
      redirectTo(action="index");
    }
  }
  
  // clubs/new
  public void function new(){
    club = model("Club").new();
  }
  
  //clubs/edit/key
  public void function edit(){
    club = model("Club").findByKey(params.key);
    	
    if (!IsObject(club)){
	    flashInsert(error="Club #params.key# was not found");
			redirectTo(action="index");
	  }
  }
  
  // clubs/create
  public void function create(){
    club = model("Club").new(params.club);
		
		if (club.save()){
			flashInsert(success="The club was created successfully.");
      redirectTo(action="index");
		} else {
		  flashInsert(error="There was an error creating the club.");
		  renderPage(action="new");
		}
  }
  
  // clubs/update
  public void function update(){
    club = model("Club").findByKey(params.key);
		
		if (club.update(params.club)){
		  flashInsert(success="The club was updated successfully.");
      redirectTo(action="index");
		} else {
		  flashInsert(error="There was an error updating the club.");
			renderPage(action="edit");
		}
  }
  
  // clubs/delete/key
  public void function delete(){
    club = model("Club").findByKey(params.key);

		if (club.delete()){
			flashInsert(success="The club was deleted successfully.");
      redirectTo(action="index");
    } else {
      flashInsert(error="There was an error deleting the club.");
			redirectTo(action="index");
    }
  }
  
}
